home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / telecomm / fido / maxpkt2.lha / MaxPKT.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1994-12-31  |  5.2 KB  |  183 lines

  1. /* Packet Maximiser 2.5 (MaxPKT) by Mat Bettinson of UK Xenolink alliance
  2.  
  3.  Xenolink (and some other tossers) has a VERY annoying habit of creating a
  4.  great deal of poxy small mail archives. This is totally unecessary and can
  5.  annoy due to the extra files, blocks required for them. Size of the outbound
  6.  file listing and the turn around time of Transfer protocols for each file.
  7.  
  8.  MaxPKT basically shoves all the waiting packets for all nodes in a single
  9.  archive for each of your systems in the outbound. 
  10.  
  11.  MaxPKT should be fairly quick and once run again will quickly decide if
  12.  there's no work to do, so is ideal for Croning and/or scripting.
  13.  
  14.  LHA and Copy and Delete should be in your path. If they AINT you have a
  15.  real weird system. :-) 
  16.  
  17.  No problems have been faced with packets deleted and not appended... Yet.
  18.  I take no responsibility for this program eating all your mail because
  19.  you have the Zimbawean version of LHA where 'c' means DELETE HD. :-)
  20.  
  21. Just modify the Outbound line below and you're away. (Must have / or : at
  22. the end as shown) 
  23.  
  24. NEW to 2.1: You can over-ride the default with an arg on the command line.
  25. IE rx MaxPKT XOUT: will treat XOUT: as your outbound.
  26.  
  27. NEW to 2.2: All files now renamed to the current date extention IE TU0.
  28.  
  29. NEW to 2.5: Checks that files are LHA archives. Oops! Should have thought
  30.             of that! Bloody PC users! :-)
  31.  
  32. NB: This script will ONLY work on packets named *.*.*.*.TH1 etc...    
  33. */
  34.  
  35. Outbound = 'BBS:temp/'
  36.  
  37. /**** Program begins. Leave alone unless feeling lucky! :-) ****/
  38.  
  39. ARG outarg
  40.  
  41. SAY ''
  42. SAY "*** MaxPKT 2.5 by Mat Bettinson of UK Xenolink Alliance, Dec '94. ***"
  43. SAY ''
  44.  
  45. If outarg = '' & Outbound = '' then DO
  46.  SAY 'Usage: [rx] MaxPKT <outbound dir>'
  47.  SAY '       or edit script header to change default.'
  48.  SAY ''
  49.  EXIT
  50.  END
  51. If outarg = '' then DO
  52.  SAY 'Using default outbound: 'Outbound
  53.  SAY ''
  54.  END
  55. ELSE DO
  56.  If Right(outarg,1) ~= ':' & Right(outarg,1) ~= '/' then outarg = outarg'/'
  57.  Outbound = outarg
  58.  END
  59. SAY 'Listing...'
  60. Address COMMAND 'LIST 'Outbound' LFORMAT "%m.%e %l" >t:Max.tmp'
  61. Numsys = 0
  62. Nothing = 1
  63. DelF = 0
  64. CALL Open(list,'t:Max.tmp','R')
  65. /* Open list of Outbound and scan for mail related files. */
  66. SAY 'Analysing...'
  67. DO forever
  68.  Line = readLN(list)
  69.  IF EOF(list) THEN break
  70.  Lsize = strip(word(line,2))
  71.  Lfile = word(line,1)
  72.  IF (Lsize ~= 'Dir') & right(Lfile,2) ~= 'UT' & (Datatype(right(Lfile,1)) = 'NUM' | right(Lfile,2) = 'LO') then DO
  73.   CALL CallCheck
  74.   END
  75.  END
  76. /* Finds the biggest packet. (No point adding a LARGE packet to a tiny one! */
  77. SAY 'Sorting...'
  78. DO i = 1 TO Numsys
  79.  NumPKT = Words(Hexname.i) - 1
  80.  last = 0
  81.  DO l = 1 TO NumPKT
  82.   TmpSize=word(Filesiz.i,l)
  83.   IF TmpSize>last THEN Biggest = l
  84.   last = TmpSize
  85.   END
  86.  IF NumPKT > 1 THEN DO
  87.   BigFile.i = word(Hexname.i,Biggest+1)
  88.   END
  89.  ELSE Bigfile.i = ''
  90.  END
  91. DO move = 1 TO NumSYS
  92.  NumPKT = words(Hexname.move) - 1
  93.  nope = 0
  94.  IF NumPKT < 2 THEN nope = 1
  95.  Del.move = ''
  96.  IF nope = 0 THEN CALL Movem
  97.  END
  98. /* After moving we better remove the Flo-file entries for the deleted packets! */
  99. IF nothing = 0 then SAY 'Fixing Flo-files...'
  100. DO move = 1 TO NumSYS
  101.  IF Del.Move ~= '' & left(Flofile.move,3) ~= 'FLO' THEN DO
  102.   CALL Open(flo,Outbound||Flofile.move,'R')
  103.   CALL Open(out,'t:Max.tmp2','W')
  104.   TodayExt = Word(Hexname.move,1)'.'UPPER(left(date('W'),2))'0'
  105.   Address COMMAND 'Rename 'Outbound||Bigfile.move' TO 'Outbound||TodayExt
  106.   Del.move = Del.move' 'Bigfile.move
  107.   Nothing = 0
  108.   DO forever
  109.    fm = READLN(flo)
  110.    IF EOF(flo) THEN break
  111.    chk = Translate(fm,'  ',':/')
  112.    floname = strip(word(chk,words(chk)))
  113.    IF INDEX(Del.move,floname) = 0 THEN CALL WriteLN(out,fm)
  114.    END
  115.   Call WriteLN(out,'^'Outbound||TodayExt)
  116.   CALL Close(flo)
  117.   CALL Close(out)
  118.   Address COMMAND 'Copy >NIL: t:Max.tmp2 'Outbound||Flofile.move
  119.   END
  120.  END
  121. IF nothing = 1 THEN DO
  122.  SAY
  123.  SAY 'No Packets to Maximize!'
  124.  END
  125. Call Close(list)
  126. Address COMMAND 'Delete >NIL: t:Max.t#?'
  127. SAY ''
  128. SAY 'MaxPKT finished. 'DelF' files deleted.'
  129. SAY ''
  130. EXIT
  131. /* The move routing... Appends the Archives to the largest */
  132. Movem:
  133. SAY 'Maxing node: 'Word(Hexname.move,1)'...'
  134. DO pkt = 1 TO NumPKT
  135.  Name = strip(word(Hexname.move,pkt+1))
  136.  IF Name ~= Bigfile.move & Datatype(right(name,1)) = 'NUM' THEN DO
  137.   Call CheckLha
  138.   IF LHA then DO
  139.    Address COMMAND 'LHA -q c 'Outbound||Bigfile.move' 'Outbound||name
  140.    Address COMMAND 'Delete >NIL: 'Outbound||name
  141.    Del.move = Del.move' 'Name
  142.    Delf = Delf + 1
  143.    END
  144.   END
  145.  END
  146. RETURN
  147. /* This validates the filenames. If a system the call Findsys */
  148. CallCheck:
  149. Parse VAR Line name size
  150. system = left(name,length(name)-4)
  151. CALL Findsys
  152. IF right(name,2) = 'LO' THEN DO
  153.  flofile.res = name
  154.  RETURN
  155.  END
  156. Hexname.res = Hexname.res' 'name
  157. Filesiz.res = Filesiz.res' 'strip(size)
  158. RETURN
  159. /* This installs new systems as they are discovered... */
  160. Findsys:
  161. DO res = 1 TO Numsys
  162.  IF word(Hexname.res,1) = system THEN RETURN
  163.  END
  164. Numsys = Numsys + 1
  165. res = Numsys
  166. Hexname.res = system
  167. Filesiz.res = ''
  168. RETURN
  169.  
  170. Call CheckLHA:
  171. archive = Outbound||name
  172. Call Open('TLHA',archive,'R')
  173. Arctest = READCH('TLHA',7)
  174. Call Close('TLHA')
  175. Arctest = Right(arctest,5)
  176. Arctest = Overlay('x',Arctest,4)
  177. If Arctest = '-lhx-' then LHA = 1
  178. ELSE DO
  179.  SAY 'WARNING: System 'Word(Hexname.move,1)' is not using LHA! Skipping...'
  180.  LHA = 0
  181.  END
  182. RETURN
  183.